﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DONGACS.Common;
using DONGACS.Domain;

namespace DONGACS.DAO
{
    public class PermissionsPublicDao : AccessData
    {
        //lấy tất cả PermissionsPublic
        public IList<PermissionsPublic> GetAllPermissionsPublic()
        {
            CommandText = "Select * From TB_PermissionsPublic as P Where P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            IList<PermissionsPublic> list = CollectionHelper.ConvertTo<PermissionsPublic>(table);
            return list;
        }

        //Thêm mới một PermissionsPublic
        public bool AddNewPermissionsPublic(PermissionsPublic PermissionsPublic)
        {
            return Insert<PermissionsPublic>("TB_PermissionsPublic", PermissionsPublic);
        }


        //Xóa tất cả PermissionsPublic
        public bool DeleteAllPermissionsPublic()
        {
            CommandText = "Delete From TB_PermissionsPublic";
            Commandtype = CommandType.Text;

            return Save();
        }


        //Xóa những PermissionsPublic có Paths
        public bool DeleteAllPermissionPublicByListPathsId(IList<int> listPathsId)
        {
            var stringListPathsId = string.Empty;
            for (int i = 0; i < listPathsId.Count; i++)
            {
                if (i == listPathsId.Count - 1)
                {
                    stringListPathsId += listPathsId[i];
                }
                else
                {
                    stringListPathsId += listPathsId[i] + ",";
                }
            }

            CommandText = "Delete From TB_PermissionsPublic Where PathId In (" + stringListPathsId + ")";

            Commandtype = CommandType.Text;

            return Save();
        }
    }
}
